package com.lucky.ebidding.controller;

import com.lucky.ebidding.model.TbInfo;
import com.lucky.ebidding.model.User;
import com.lucky.ebidding.model.UserShInfo;
import com.lucky.ebidding.model.ZbInfo;
import com.lucky.ebidding.service.TbService;
import com.lucky.ebidding.service.UserService;
import com.lucky.ebidding.service.ZbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * ClassName:TbController
 * Package:com.lucky.ebidding.controller
 * Description:
 *
 * @Date:2020/4/16 20:05
 * @Author:857251389@qq.com
 */
@Controller
public class TbController {

    @Autowired
    private TbService tbService;

    @Autowired
    private ZbService zbService;

    @Autowired
    private UserService userService;

    @GetMapping("/tb/apply/{id}")
    public String apply(@PathVariable(name = "id") Integer id, Model model) {

        model.addAttribute("zbId", id);
        return "tb/tb_apply";
    }


    @PostMapping("/tb/fileInsert/{tbId}")
    public String insertTbFile(TbInfo tbInfo, @PathVariable(name = "tbId") Integer tbId) {

        tbService.update(tbInfo);

        return "redirect:/";
    }

    @PostMapping("/tb/signUp")
    public String signIp(TbInfo tbInfo) {

        tbService.insert(tbInfo);

        return "redirect:/";
    }

    @GetMapping("/tb/fileUploadJump/{zbId}")
    public String tbFileUpLoadJump(@PathVariable(name = "zbId") Integer zbId, Model model,
                                   HttpServletRequest request) {
        User user = (User) request.getSession().getAttribute("user");

        TbInfo tbInfo = tbService.selectTbInfoByIdAndZbId(user.getId(), zbId);
        model.addAttribute("tbInfo",tbInfo);
        model.addAttribute("id",zbId);
        return "tb/tb_fileUpLoad";
    }

    @GetMapping("/tbAddJump")
    public String tbAddJump(HttpServletRequest request,Model model){
        User user = (User) request.getSession().getAttribute("user");

        UserShInfo userShInfo = userService.selectUserShInfoByUserId(user.getId());

        model.addAttribute("userShInfo",userShInfo);
        return "tb/tb_sh_file_add";
    }


}
